﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using SIPO.Library;
using SIPO.Library.DomainObject.Administration.Catalog;
using SIPO.Library.Enum;
using SIPO.Library.Interfaces;

namespace SIPO.Library.DataAccess.Administration.Catalog
{
    public partial class recRegistrationEmisionTypeRepo
    {
        public List<recRegistrationEmisionType> GetList(short isPublicCompany)
        {
            List<recRegistrationEmisionType> tt = new List<recRegistrationEmisionType>();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT RegistrationEmisionTypeID, RegistrationEmisionTypeName FROM master.recRegistrationEmisionType where IsPublicCompany = " + isPublicCompany;
                    cmd.CommandType = CommandType.Text;
                    try
                    {
                        conn.Open();
                        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (dr.Read())
                            {
                                recRegistrationEmisionType t = new recRegistrationEmisionType();
                                t.RegistrationEmisionTypeID = dr[recRegistrationEmisionType.Fields.RegistrationEmisionTypeID] == DBNull.Value ? (short)0 : short.Parse(dr[recRegistrationEmisionType.Fields.RegistrationEmisionTypeID].ToString());
                                t.RegistrationEmisionTypeName = dr[recRegistrationEmisionType.Fields.RegistrationEmisionTypeName] == DBNull.Value ? string.Empty : dr[recRegistrationEmisionType.Fields.RegistrationEmisionTypeName].ToString();
                                
                                tt.Add(t);
                                t.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }
                }
            }
            return tt;
        }
    }
}
